﻿using ModuleA.Event;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ModuleA.Views
{
    /// <summary>
    /// ViewC.xaml 的交互逻辑
    /// </summary>
    public partial class ViewC : UserControl
    {
        private IEventAggregator eventAggregator;

        public ViewC(IEventAggregator eventAggregator)
        {
            InitializeComponent();
            eventAggregator.GetEvent<MessageEvent>().Subscribe(SubMessage);//订阅这个函数
            this.eventAggregator = eventAggregator;
        }

        private void SubMessage(string obj)
        {
            MessageBox.Show($"接受到的消息为：{obj}");//在接受到消息后取消订阅
            eventAggregator.GetEvent<MessageEvent>().Unsubscribe(SubMessage);

        }
    }
}
